package com.atguigu.controller;

import com.atguigu.commonutils.R;
import com.atguigu.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/fileoss")
public class OssController {

    //访问地址：http://localhost:8002/eduoss/fileoss
    //Swagger 测试地址: http://localhost:8002/swagger-ui.html
    @Autowired
    private OssService ossService;

    //上传头像
    @PostMapping
    public R uploadOssFile(MultipartFile file){
        //获取上传的文件   MultipartFile
        String avatarUrl = ossService.uploadFileAvatar(file);   //获取上传阿里云后的图片的路径
        return R.ok().data("url",avatarUrl);
    }

}
